package org.example.rabbitmq.provider.controller;

import org.example.rabbitmq.provider.mq.MessagePublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProviderController {
    @Autowired
    MessagePublisher publisher;

    @RequestMapping("/")
    public String home() {
        return "/provider/publish?tenantId={tenantId}&message={message}";
    }

    @RequestMapping("/provider/publish")
    public String publish(@RequestParam("tenantId") String tenantId, @RequestParam("message") String message) {
        try {
            publisher.publish(tenantId, message);
        } catch (Exception ex) {
            return "FAILED";
        }
        return "OK";
    }
}
